package yto.freemarker.bootrocketmq;


import com.dongxing.springbootrocketmqstarter.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import yto.freemarker.bootrocketmq.config.RocketMQOtherTemplate;

@SpringBootApplication
public class ProducerRocketmqApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(ProducerRocketmqApplication.class, args);
    }

    @Autowired
    private RocketMQTemplate rocketMQTemplate;


    //和自定义的多个不同的mq共同使用
    @Autowired
    private RocketMQOtherTemplate otherTemplate;


    @Override
    public void run(String... args) throws Exception {

        // Rocket默认开启了VIP通道，VIP通道端口为10911-2=10909, 若Rocket服务器未启动端口10909或者防火墙为关闭，则报connect to <：10909> failed
        // rocketMQTemplate.getProducer().setVipChannelEnabled(false);
//        String message = "你好！！";
        while (true) {
//        SendResult send = otherTemplate.getProducer().send(new Message("test-topic-1", message.getBytes()));
//        System.out.println(JSON.toJSONString(send));
            rocketMQTemplate.sendOneWay("test-topic-3", "test3", "MQ测试", null);
            System.out.println("数据发送成功===============================================");
        }
    }
}
